/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CCPVSimulationRootPanelPackage;

import java.awt.Component;
import java.util.Vector;

/**
 * Helps keep track of disabled atlruism values for the right click
 * popup menu 
 * @author Heather
 */
public class DisabledAltruism
{
  // this is the component which a particular list of disabled altruism groups
  // are associated w/

  public Vector<Component> associatedComponents;
  // These are the actual names of the disabled entries
  public Vector<Vector<String>> disabledGroups;

  public DisabledAltruism()
  {
    associatedComponents = new Vector<Component>();
    disabledGroups = new Vector<Vector<String>>();
  }

  public Vector<String> getDisbledGroupOfX (Component x)
  {
    Vector<String> ret = new Vector<String>();

    int location = associatedComponents.indexOf(x);
    if (location != -1)
    {
      ret = disabledGroups.get(location);
    }

    return ret;
  }

  // Add a string to tbe disabled on the associated component
  public void addEntry(Component c, String s)
  {
    int location = associatedComponents.indexOf(c);
    if (location != -1)
    {
      Vector<String> cDisabled = disabledGroups.get(location);
      if (!cDisabled.contains(s))
        disabledGroups.get(location).add(s);
    } // else we need to add a new entry to the vector
    else
    {
      associatedComponents.add(c);
      Vector<String> newDisabled = new Vector<String>();
      newDisabled.add(s);
      disabledGroups.add(newDisabled);
    }
  }

  public void removeComponent(Component c)
  {
    int location = associatedComponents.indexOf(c);

    if (location != -1)
    {
      associatedComponents.remove(location);
      disabledGroups.remove(location);
    }
  }

  public void removeDisabledEntry(Component c, String s)
  {
    int location = associatedComponents.indexOf(c);

    if (location != -1)
    {
      Vector<String> disabledStrings = disabledGroups.get(location);
      if (disabledStrings.contains(s))
        disabledStrings.remove(s);
    }
  }

  // clears the altruism list for this component
  public void clearDiabledFromX(Component x)
  {
    int location = associatedComponents.indexOf(x);

    if (location != -1)
    {
      disabledGroups.get(location).clear();
    }
  }

  // copies one component's disabled list to another.  If component B
  // does not exist in the list, it adds it
  public void copyDisabledFromAToB (Component A, Component B)
  {
    int locationA = associatedComponents.indexOf(A);
    int locationB = associatedComponents.indexOf(B);

    if (locationA != -1)
    {
      if (locationB != -1)
      {
        Vector<String> aDisabled = disabledGroups.get(locationA);
        Vector<String> bDisabled = disabledGroups.get(locationB);
        bDisabled.clear();

        for(int i = 0; i < aDisabled.size(); i++)
        {
          bDisabled.add(aDisabled.get(i));
        }
      }
      else
      {
        Vector<String> aDisabled = disabledGroups.get(locationA);
        Vector<String> bDisabled = new Vector<String>();

        for(int i = 0; i < aDisabled.size(); i++)
        {
          bDisabled.add(aDisabled.get(i));
        }

        associatedComponents.add(B);
        disabledGroups.add(bDisabled);
      }
    }
  }
}
